<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>循环迭代对象</title>
    <script>
      /*
       *    可迭代的对象
       *    迭代的方法
       */
      let list = [10, 20, 30];
      let str = "你好呀";
      let mymap = new Map();
      mymap.set("JS", "Javascript");
      mymap.set("PL", "Perl");
      mymap.set("PY", "Python");

      for (let val of list) {
        console.log(val);
        /*
         * 10
         * 20
         * 30
         */
      }
      for (let val of str) {
        console.log(val);
        /*
         * 你
         * 好
         * 呀
         */
      }
      for (let [key, val] of mymap) {
        console.log(key, val);
        /*
         * JS Javascript
         * PL Perl
         * PY Python
         */
      }
      let it = mymap.values(); //拿到键值
      let tmp;
      while ((tmp = it.next())) {
        if (tmp.done) break;
        // console.log(tmp.value, tmp.done);
        /*
         * Javascript false
         * Perl false
         * Python false
         */
        console.log(tmp);
        /*
         * {value: "Javascript", done: false}
         * {value: "Perl", done: false}
         * {value: "Python", done: false}
         */
      }
    </script>
  </head>
  <body></body>
</html>
